<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<form method="get" class="form-inline m-b-xs" action="<?php echo url('order-cash');?>">
	<div class="row">
		<div class="col-lg-1">
			<div class="form-group" style="width:100%;">
				<select name="status" class="form-control" style="width:100%;">
					<option value="-1">全部</option>
					<option value="已审核" <?php if($status=='已审核'){echo 'selected';} ?>>已审核</option>
					<option value="已拒绝" <?php if($status=='已拒绝'){echo 'selected';} ?>>已拒绝</option>
					<option value="待审核" <?php if($status=='待审核'){echo 'selected';} ?>>待审核</option>
				</select>
			</div>
		</div>
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="number" placeholder="订单号" value="<?php echo $number?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="order_username" placeholder="商户帐号" value="<?php echo $order_username;?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-4">
			<div class="form-group">
				<div class="input-group" style="background-color:#fff;">
					<span class="input-group-addon"><i class="icon icon-calendar"></i></span>
					<input type="text" name="fdate" class="form_datetime form-control" value="<?php echo $fdate;?>">
					<span class="input-group-addon">至</span>
					<input type="text" name="tdate" class="form_datetime form-control" value="<?php echo $tdate;?>">
				</div>
			</div>
		</div>
		<div class="col-lg-2">
			<button type="submit" class="btn btn-success" style="width:100%;">
				<i class="icon icon-search"></i>
				立即查询
			</button>
		</div>
		<div class="col-lg-1">
			<a class="btn btn-info" href="<?php echo url('order-cash').$param.'&export=1';?>">导出</a>
		</div>
	</div>
</form>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th class="text-center">订单号</th>
							<th class="text-center">商户账户</th>
							<th class="text-center">金额</th>
							<th class="text-center">手续费</th>
							<th class="text-center">银行</th>
							<th class="text-center">银行账号</th>
							<th class="text-center">收款人</th>
							<th class="text-center">提现时间</th>
							<th class="text-center">订单状态</th>
							<th class="text-center">处理人</th>
							<th class="text-center">处理时间</th>
							<th class="text-center">操作</th>
						</tr>
					</thead>
					<tbody id="userlist">
                      	<?php $count_success = $count_fail = $count_now = $coin_success = $coin_fail = $coin_now = 0; ?>
						<?php if($log){foreach($log as $l){ ?>
						<?php $span = '<span>';?>
						<?php if($l['status']=='已审核'){$span = '<span style="color:#16a085;">'; $count_success += 1; $coin_success += $l['coin']; } ?>
						<?php if($l['status']=='已拒绝'){$span = '<span style="color:#ea413c;">'; $count_fail += 1; $coin_fail += $l['coin'];} ?>
                      	<?php if($l['status']=='待审核'){$count_now += 1; $coin_now += $l['coin'];} ?>
						<tr uid="<?php echo $l['id']; ?>">
							<td class="text-center">
								<a href="javascript:;" onclick="$(this).parent().find('div').toggle()">显示</a>
								<div style="display:none;"><?php echo $l['number']; ?></div>
							</td>
							<td class="text-center"><?php echo $l['username']; ?> </td>
							<td class="text-center"><?php echo $l['coin']; ?> </td>
							<td class="text-center"><?php echo $l['fee']; ?> </td>
							<td class="text-center"><?php echo $l['bank']; ?><?php if($l['is_dai']==1){echo '(代付)';} ?></td>
							<td class="text-center"><?php echo $l['code']; ?></td>
							<td class="text-center"><?php echo $l['name']; ?></td>
							<td class="text-center"><?php echo date('m-d H:i:s',$l['time']); ?></td>
							<td class="text-center"><?php echo $span; ?><?php echo $l['status']; ?></span><br><?php echo $l['type_name']; ?></td>
							<td class="text-center"><?php echo $l['do_username']; ?></td>
							<td class="text-center"><?php echo $l['do_time']?date('m-d H:i:s',$l['do_time']):''; ?></td>
							<td class="text-center">
								<?php if($l['status']=='待审核'){ ?>
								<a href="javascript:;" class="deal-apply" data-toggle="modal" data-target="#myModal" data-href="<?php echo url("order-cash-已审核-$l[id]"); ?>" style="color:#2ecc71;font-weight:bold;">通过</a>
								<a href="javascript:;" class="deal-refuse" data-href="<?php echo url("order-cash-已拒绝-$l[id]"); ?>" style="color:#ea413c;font-weight:bold;">拒绝</a>
								<?php } ?>
							</td>
						</tr>
						<?php }} ?>
          				<tr>
                          	<td></td>
                          	<td class="text-center">合计</td>
                          	<td class="text-center"><?php echo $total['cash_total']?$total['cash_total']:0; ?> </td>
                          	<td class="text-center"><?php echo $total['cash_fee']?$total['cash_fee']:0; ?> </td>
                          	<td colspan="8"></td>
                        </tr>
          				<!--<tr>
                          	<td colspan="1"></td>
                        	<td colspan="4" class="text-center">成功订单数：<?php echo $count_success;?>单</td>  
                          	<td colspan="6" class="text-center">成功订单金额：<?php echo $coin_success;?>元</td>  
                        </tr>
          				<tr>
                          	<td colspan="1"></td>
                          	<td colspan="4" class="text-center">失败订单数：<?php echo $count_fail;?>单</td>  
                          	<td colspan="6" class="text-center">失败订单金额：<?php echo $coin_fail;?>元</td> 
                        </tr>
          				<tr>
                          	<td colspan="1"></td>
                          	<td colspan="4" class="text-center">待审订单数：<?php echo $count_now;?>单</td>  
                      		<td colspan="6" class="text-center">待审订单金额：<?php echo $coin_now;?>元</td>  
                        </tr>-->
					</tbody>
				</table>
			</div>
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
			<div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">类型</h4>
            </div>
			<div class="modal-body">
				<input type="hidden" id="data-href" value="">
				<div class="form-group row">
					<label class="col-md-3 control-label">支付宝通道：</label>
					<div class="col-lg-8">
						<select id="type_channel" name="type_channel" class="form-control">
							<option value="">选择通道</option>
							<?php foreach($channels as $l){ ?>
							<option value="<?php echo $l['name'];?>"><?php echo $l['name'];?></option>
							<?php } ?>
						</select>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-md-3 control-label">银行：</label>
					<div class="col-lg-8">
						<select id="type_bank" name="type_bank" class="form-control">
							<option value="">选择银行</option>
							<?php foreach($conf['type_bank'] as $_bank){ ?>
							<option value="<?php echo $_bank;?>"><?php echo $_bank;?></option>
							<?php } ?>
						</select>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="deal-apply">确认通过</button>
			</div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<link rel="stylesheet" href="../view/css/datetimepicker.css?r=1">
<script src="../view/js/datetimepicker.js?r=1" type="text/javascript"></script>
<script>
//日期插件
$(".form_datetime").datetimepicker({
	language:  'zh',
	format: 'mm/dd/yyyy',//显示格式
	todayHighlight: 1,//今天高亮
	minView: "month",//设置只显示到月份
	startView:2,
	forceParse: 0,
	autoclose: 1//选择后自动关闭
});

$('.deal-refuse').click(function(){
	if(confirm('确认拒绝该订单吗？')){
		$.xpost($(this).attr('data-href'), function(code, message){
			$.alert(message);
			if(code==1) setTimeout(function(){window.location.reload()}, 1500);
		});
	}
});

$('.deal-apply').click(function(){
	$('#data-href').val($(this).attr('data-href'));
});
$('#deal-apply').click(function(){
	$.xpost($('#data-href').val(), {type_channel:$('#type_channel').val(),type_bank:$('#type_bank').val()}, function(code, message){
		$.alert(message);
		if(code==1) setTimeout(function(){window.location.reload();}, 1500);
	});
});

$('#nav_pc li.order, #nav_mobile li.order').tab('show');
</script>